﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Net;

namespace ThresholdAssistant.Http
{
    /// <summary>
    /// Http客户端请求工具类
    /// </summary>
    public static class HttpClientManager
    {
        /// <summary>
        /// 使用Polly服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="defaultConnectionLimit">全局的连接数上限(默认：1000)</param>
        public static IServiceCollection AddHttpClientUtil(this IServiceCollection services, int defaultConnectionLimit = 1000)
        {
            services.AddHttpClient();
            services.AddHttpContextAccessor();
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            ServicePointManager.DefaultConnectionLimit = defaultConnectionLimit;
            return services;
        }
    }
}